package org.utils.io;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class ReadLineUtils
{
    public static String getString(String label) throws IOException
    {
	 System.out.print(label);
	 BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
	 String line = reader.readLine();
	 //reader.close();
	 return line;
    }

    public static String[] getStringArray(String label) throws IOException
    {
	 int size;
	 String tmp;
	 tmp = getString(label + ": how large? ");
	 size = Integer.parseInt(tmp);

	 String[] strArray = new String[size];
	 for(int i = 0; i < size; i++){
	     strArray[i] = getString(label +"[" + i + "] = ");
	 }
	 return strArray;
    }

    public static String[][] getStringTable(String label) throws IOException
    {
	 int rows = 0, cols = 0;
	 String tmp;
	 tmp = getString(label + ": how many rows? ");
	 rows = Integer.parseInt(tmp);
	 tmp = getString(label + ": how many cols? ");
	 cols = Integer.parseInt(tmp);

	 String[][] strTable = new String[rows][cols];
	 for(int i = 0; i < rows; i++){
	     for(int j = 0; j < cols; j++){
		  strTable[i][j] = getString(label+"["+i+"]["+j+"]");
	     }
	 }
	 return strTable;
    }
}
